﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;

namespace Lrd.Permissions.Repository
{
    public class DbContextBase : DbContext
    {
        private readonly IServiceProvider _serviceProvider =null;
        private readonly IEntityManager _entityManager = null;
        protected DbContextBase(DbContextOptions options, IEntityManager entityManager, IServiceProvider serviceProvider)
                : base(options)
        {
            _serviceProvider = serviceProvider;
            _entityManager = entityManager;
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            Type contextType = GetType();
             var mappings= _entityManager.GetEntityRegisters(contextType);

            foreach (var item in mappings)
            {
                item.Map(modelBuilder);
            }

        }


      


    }
}
